package controls;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import pages.WebPage;
import reports.Report;

import utils.Events;

public class ListBox {
	private WebElement listBox;
	private By by;
	public Events events;

	public ListBox(String list, String desc, ElementFinder util, Events events) {
		this.events = events;
		if (list.startsWith("id")) {
			listBox = util.findElementByID(list);
		}

		else if (list.startsWith("css")) {
			listBox = util.findElementByCss(list);
		}

		else if (list.startsWith("//")) {
			listBox = util.findElementByXpath(list);
		}
		WebPage.elementList.put(listBox, desc);
	}

	public ListBox(String list, String desc, By by, ElementFinder util,
			Events events) {
		this.events = events;
		this.by = by;
		if (list.startsWith("id")) {
			listBox = util.findElementByID(list);
		}

		else if (list.startsWith("css")) {
			listBox = util.findElementByCss(list);
		}

		else if (list.startsWith("//")) {
			listBox = util.findElementByXpath(list);
		}
		WebPage.elementList.put(listBox, desc);
	}
	
	public void dragAndDrop(){
		
	}
	
	/**
	 * This method will return the By of the List Box
	 * 
	 * @author Pradeep Sundaram
	 * @return By
	 */
	public By getBy() {
		return by;
	}
	
	/**
	 * This method will return the webElement of the ListBox
	 * 
	 * @author Pradeep Sundaram
	 * @return WebElement
	 */
	public WebElement getWebElement() {
		return listBox;
	}
	
	/**
	 * will return boolean based on the presence of the button
	 * 
	 * @author Pradeep Sundaram
	 * @return boolean
	 */
	public boolean isDisplayed() {
		Report.log("Checking whether the field "
				+ WebPage.elementList.get(listBox) + " is displayed.<BR>");
		return listBox.isDisplayed();
	}

	/**
	 * This method will return the tool tip of the button
	 * 
	 * @author PSubramani33
	 * @return String
	 */
	public String getToolTip() {
		Report.log("Getting the tool tip of the field "
				+ WebPage.elementList.get(listBox) + ".<BR>");
		return listBox.getAttribute("title");
	}
	
}
